// 类 : 方法
class CommonUtil {
  // 获取随机数
  getRandom(min: number, max: number): number {
    return Math.floor(Math.random() * (max - min) + min);
  }
}
// const : 优化枚举 编译之后 没有编译的代码
const enum Code {
  success = 200,
  unToken = 401,
  badRequest = 400,
  unAuthor = 403,
  serverError = 500,
}

class HandleCode<T> extends CommonUtil {
  handleClick(code: Code) {
    const oDiv = document.createElement("div");
    oDiv.style.position = 'absolute'
    switch (code) {
      case Code.success:
        // 处理成功的逻辑
        oDiv.style.width = this.getRandom(50,200)+'px'
        oDiv.style.height = this.getRandom(50,200)+'px'
        oDiv.style.left = this.getRandom(0,1200)+'px'
        oDiv.style.top = this.getRandom(0,500)+'px'
        oDiv.style.backgroundColor = "#00ff00"
        oDiv.innerHTML = code + "";
        break;
      case Code.unToken:
        // 处理成功的逻辑
        break;
      case Code.badRequest:
        // 处理成功的逻辑
        break;
      case Code.unAuthor:
        // 处理成功的逻辑
        break;
      case Code.serverError:
        // 处理成功的逻辑
        break;
    }
    document.body.appendChild(oDiv)
  }
}

const handle = new HandleCode()